package com.xiaoyu.serviceImpl;

import com.xiaoyu.ClassDao;
import com.xiaoyu.StudentDao;
import com.xiaoyu.client.Class_TeacherDao;
import com.xiaoyu.client.Class_Teacher_CourseDao;
import com.xiaoyu.model.Class;
import com.xiaoyu.model.Course;
import com.xiaoyu.model.Teacher;
import com.xiaoyu.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassDao classDao;
    @Autowired
    private StudentDao studentDao;
    @Autowired
    private Class_Teacher_CourseDao classTeacherCourseDao;
    @Autowired
    private Class_TeacherDao classTeacherDao;
    @Override
    public List<Class> allClass() {
        return classDao.findClass(null);
    }

    @Override
    public Boolean updateClass(Class aClass) {
        if(classDao.updateClass(aClass)==1)
            return true;
        return false;
    }

    @Override
    public Boolean deleteClass(Class aClass) {
        classTeacherCourseDao.delete(aClass.getId());
        classTeacherDao.delete(aClass.getId());
        if(classDao.deleteClass(aClass)==1)
            return true;
        return false;
    }

    @Override
    public Boolean addClass(Class aClass) {
        if(classDao.addClass(aClass)==1)
            return true;
        return false;
    }

    @Override
    public Boolean updateCourseOfClassWithTeacher(Class aClass, Teacher teacher, Course course) {
            classTeacherCourseDao.update(aClass.getId(),teacher.getId(),course.getId());
            classTeacherDao.update(aClass.getId(),teacher.getId());
            return true;
    }

    @Override
    public Class findOneClass(Class aClass) {
        return classDao.findOneClass(aClass);
    }

    @Override
    public List<Class> findSomeClass(Teacher t) {
        return classDao.findSomeClass(t);
    }

    @Override
    public List<Class> allInfo() {
        return classDao.allInfo();
    }
}
